package com.will.seed.controller;

import com.will.seed.common.TestWebSocketHandler;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.socket.TextMessage;
import org.springframework.web.socket.WebSocketSession;

import java.io.IOException;

/**
 * Created by Administrator on 2018/7/26.
 */
@RestController
@RequestMapping("/")
public class RootController {

    @RequestMapping("/a")
    public String a() {
        return "a";
    }

    @RequestMapping("/test")
    public String test(@RequestParam(value = "msg") String message){
        for(WebSocketSession session: TestWebSocketHandler.clientSessionMap.values()){
            try {
                session.sendMessage(new TextMessage(message));
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return "test";
    }



}
